package wsz.rocketMq.controller;

import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import wsz.rocketMq.service.OrderService;

/**
 * 订单业务
 * @author wsz
 * @date 2022/3/2 11:20
 **/
@Controller
@RequestMapping("order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 所有订单
     * @param model
     * @return
     */
    @GetMapping("")
    public String findById(Model model) {
        model.addAttribute("orderList", orderService.allOrder());
        return "order";
    }

    /**
     * 获取订单信息
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public String findById(@PathVariable Long id, Model model) {
        model.addAttribute("order", orderService.findById(id));
        return "orderInfo";
    }

    /**
     * 订单支付
     * @param id
     * @return
     */
    @ResponseBody
    @GetMapping("/pay/{id}")
    public JSONObject orderPay(@PathVariable Long id) {
        return orderService.orderPay(id);
    }
}
